package com.ltx.blog_ltx.controller;


import com.alibaba.fastjson.JSONObject;
import com.ltx.blog_ltx.entity.Answer;
import com.ltx.blog_ltx.entity.dto.OJDto;
import com.ltx.blog_ltx.entity.dto.Rank;
import com.ltx.blog_ltx.mapper.OJMapper;
import com.ltx.blog_ltx.mapper.UserMapper;
import com.ltx.blog_ltx.server.OJ_CServer;
import com.ltx.blog_ltx.server.OJ_CppServer;
import com.ltx.blog_ltx.server.OJ_JavaServer;
import com.ltx.blog_ltx.until.FileUntil;
import com.ltx.blog_ltx.until.ItemSimilarity;
import com.ltx.blog_ltx.until.jwtUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;

@RestController
public class OJController {
    @Autowired
    private OJMapper ojMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/getAllOJ")
    public Map<String, Object> allOJ(@RequestBody JSONObject param){
        String user_token = param.getString("user_token");
        String userName = jwtUntil.getTokenName(user_token);
        int userId = userMapper.queryIdByName(userName);
        Integer startingNumber = param.getInteger("StartingNumber");
        System.out.println(startingNumber);
        List<OJDto> ojDtos = new ArrayList<OJDto>();
        if(startingNumber==1){
             ojDtos = ojMapper.allOj(userId, 0);
        }else {
             ojDtos = ojMapper.allOj(userId, (startingNumber-1)*10-1);
        }
        DecimalFormat df=new DecimalFormat("0.0");
        for (int i = 0; i < ojDtos.size(); i++) {
            if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                ojDtos.get(i).setPassingRate("0.0%");
                }else{
                ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");

            }
        }
        Map<String, Object> Map = new HashMap<>();
        Map.put("ojDtos",ojDtos);
        Integer total = ojMapper.ojNum();
        Map.put("total",total);
        return Map;
    }

    @PostMapping("/commonOj")
    public Map<String, Object> CommonOj(@RequestBody JSONObject param){
        Integer startingNumber = param.getInteger("StartingNumber");
        HashMap<String, Object> Map = new HashMap<>();
        List<OJDto> ojDtos;
        if(startingNumber==1){
            ojDtos = ojMapper.CommonOJ(0);
        }else {
            ojDtos = ojMapper.CommonOJ((startingNumber - 1) * 10 - 1);
        }
        DecimalFormat df=new DecimalFormat("0.0");
        for (int i = 0; i < ojDtos.size(); i++) {
            if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                ojDtos.get(i).setPassingRate("0.0%");
            }else{
                ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");
            }
        }
        System.out.println(ojDtos);
        Map.put("ojDtos",ojDtos);
        Integer total = ojMapper.ojNum();
        Map.put("total",total);
        return Map;
    }

    @PostMapping("/problemInfo")
    public Map<String,Object> ProblemInfo(@RequestBody JSONObject param) throws FileNotFoundException {
        HashMap<String, Object> Map = new HashMap<>();
        Integer oj_id = param.getInteger("oj_id");
        redisTemplate.opsForList().rightPush("heats",String.valueOf(oj_id));     //当用户去做题的时候就添加题目的id到redis里面，设置一个定时访问这些list找到访问最多的id
        String path = ojMapper.ojDescription(oj_id);
        System.out.println(path);
        String str = null;
        try {
            //自定义md2Html函数转化md文件为html
            str = FileUntil.md2Html(path,"http://localhost:5001/assets/");
            System.out.println(str);
        } catch (IOException e) {
            e.printStackTrace();
            //抛出自已定义的异常
            throw new FileNotFoundException("文件所在路径找不到文件");
        }
        System.out.println(str);
        Map.put("msg",str);
        String CTemplateCode = ojMapper.ojCTemplateCode(oj_id, oj_id);
        Map.put("CTemplateCode",CTemplateCode);
        return Map;
    }

    @PostMapping("/problemInfo2")
    public Map<String,Object> ProblemInfo2(@RequestBody JSONObject param) throws FileNotFoundException {
        HashMap<String, Object> Map = new HashMap<>();
        String oj_topic = param.getString("oj_topic");
        int oj_id = ojMapper.queryIdByTopic(oj_topic);
        redisTemplate.opsForList().rightPush("heats",String.valueOf(oj_id));     //当用户去做题的时候就添加题目的id到redis里面，设置一个定时访问这些list找到访问最多的id
        String path = ojMapper.ojDescription(oj_id);
        System.out.println(path);
        String str = null;
        try {
            //自定义md2Html函数转化md文件为html
            str = FileUntil.md2Html(path,"http://localhost:5001/assets/");
            System.out.println(str);
        } catch (IOException e) {
            e.printStackTrace();
            //抛出自已定义的异常
            throw new FileNotFoundException("文件所在路径找不到文件");
        }
        System.out.println(str);
        Map.put("msg",str);
        String CTemplateCode = ojMapper.ojCTemplateCode(oj_id, oj_id);
        Map.put("CTemplateCode",CTemplateCode);
        return Map;
    }

    @PostMapping("/sreachProblem")
    public List<OJDto> sreachProblem(@RequestBody JSONObject param){
        String sreachcontent = param.getString("sreachcontent");
        List<OJDto> ojDtos = ojMapper.sreachProblem(sreachcontent);
        DecimalFormat df=new DecimalFormat("0.0");
        for (int i = 0; i < ojDtos.size(); i++) {
            if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                ojDtos.get(i).setPassingRate("0.0%");
            }else{
                ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");
            }
        }
        return ojDtos;
    }

    @PostMapping("/changeDifficulty")
    public List<OJDto> changeDifficulty(@RequestBody JSONObject param){
        String difficulty = param.getString("difficulty");
        if(difficulty.equals("选项1")){
            difficulty="简单";
        }else if(difficulty.equals("选项2")){
            difficulty="中等";
        }else{
            difficulty="困难";
        }
        List<OJDto> ojDtos = ojMapper.changeDifficulty(difficulty);
        DecimalFormat df=new DecimalFormat("0.0");
        for (int i = 0; i < ojDtos.size(); i++) {
            if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                ojDtos.get(i).setPassingRate("0.0%");
            }else{
                ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");
            }
        }
        return ojDtos;
    }

    @PostMapping("/changeType")
    public String changeType(@RequestBody JSONObject param){
        String type = param.getString("type");
        Integer id = param.getInteger("id");
        String TemplateCode="";
        if(type.equals("c")){
            TemplateCode=ojMapper.ojCTemplateCode(id,id);
        }else if(type.equals("c++")){
            TemplateCode=ojMapper.ojCppTemplateCode(id,id);
        }else if(type.equals("java")){
            TemplateCode=ojMapper.ojJavaTemplateCode(id,id);
        }
        return TemplateCode;
    }

    @PostMapping("/promblemName")
    public String promblemName(@RequestBody JSONObject param){
        Integer id = param.getInteger("id");
        return ojMapper.problemName(id);
    }

    @PostMapping("/summitIdea")
    public Map<String,Object> SummitIdea(@RequestBody JSONObject param) throws IOException {
        HashMap<String, Object> Map = new HashMap<>();
        String areatext = param.getString("areatext");
        String type1 = param.getString("type");
        Integer id = param.getInteger("id");
        String tokenName = jwtUntil.getTokenName(param.getString("user_token"));
        int userId = userMapper.queryIdByName(tokenName);
        ojMapper.addSubmitNum(id);   //提交人数加一
        if(type1.equals("c")){
            String s = ojMapper.ojCReplaceStr(id, id);
            if(s!=null){
                String doc=areatext.replace(s,ojMapper.ojCTestCode(id,id));
                Answer answer = OJ_CServer.returnAnswer(doc);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if((reason.equals("编译错误"))){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==null){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    cmdout=cmdout.replace("\n","");
                    String output = ojMapper.ojExpectedOutput(id);
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        ojMapper.addSubmitNum(id);        //正确结果加一
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }

            }else {
                Answer answer = OJ_CServer.returnAnswer(areatext);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if((reason.equals("编译错误"))){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    cmdout=cmdout.replace("\n","");
                    String output = ojMapper.ojExpectedOutput(id);
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }
            }
        }else if(type1.equals("c++")){
            String s = ojMapper.ojCppReplaceStr(id, id);
            if(s!=null){
                String doc=areatext.replace(s,ojMapper.ojCppTestCode(id,id));
                Answer answer = OJ_CppServer.returnAnswer(doc);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if((reason.equals("编译错误"))){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    String output = ojMapper.ojExpectedOutput(id);
                    cmdout=cmdout.replace("\n","");
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }

            }else {
                Answer answer = OJ_CppServer.returnAnswer(areatext);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if((reason.equals("编译错误"))){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    cmdout=cmdout.replace("\n","");
                    String output = ojMapper.ojExpectedOutput(id);
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }
            }
        }else  if(type1.equals("java")){
            String s = ojMapper.ojJavaReplaceStr(id, id);
            if(s!=null){
                String doc=areatext.replace(s,ojMapper.ojJavaTestCode(id,id));
                Answer answer = OJ_JavaServer.returnAnswer(doc);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if(reason.equals("编译错误")){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    cmdout=cmdout.replace("\n","");
                    String output = ojMapper.ojExpectedOutput(id);
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }

            }else {
                Answer answer = OJ_JavaServer.returnAnswer(areatext);
                String reason = answer.getReason();//编译错误还是运行错误还是运行成功
                Map.put("reason",reason);
                if((reason.equals("编译错误"))){
                    String cmdout = answer.getStderr();//编译错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",0);          //type参数是用来判断是哪一种情况的，0表示编译错误，1表示结果正确，2表示结果错误，3表示运行时错误
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }else  if(reason.equals("运行成功")){
                    String cmdout = answer.getStdout();//程序的输出
                    cmdout=cmdout.replace("\n","");
                    String output = ojMapper.ojExpectedOutput(id);
                    if(output.equals(cmdout)){
                        Map.put("cmdout",cmdout);
                        Map.put("success","结果正确");
                        Map.put("type",1);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,1);
                        }else {
                            ojMapper.updateState(userId,id,1);
                        }
                    }else {
                        Map.put("cmdout",cmdout);
                        Map.put("error","结果错误");
                        Map.put("type",2);
                        if(ojMapper.isExistDoOj(userId,id)==0){
                            ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                        }
                    }
                }else {     //运行错误的情况
                    String cmdout = answer.getStderr();//运行错误的情况的输出
                    cmdout=cmdout.replace("\n","");
                    Map.put("cmdout",cmdout);
                    Map.put("type",3);
                    if(ojMapper.isExistDoOj(userId,id)==0){
                        ojMapper.insertState((int) ((Math.random() * 9 + 1) * 100000),userId,id,0);
                    }
                }
            }
        }
        return Map;
    }

    @PostMapping("/recommend")
    public List<OJDto> Recommend(@RequestBody JSONObject param){
        String user_token = param.getString("user_token");
        String tokenName = jwtUntil.getTokenName(user_token);
        int userId = userMapper.queryIdByName(tokenName);
        Integer OjNumById = ojMapper.ojNumById(userId);
        Integer OjSum = ojMapper.ojNum();
        if(((float)OjNumById/(float)OjSum)*100>15){                  //如果用户做的题目大于了就采用基于物品的协同过滤算法进行推荐
            ArrayList<OJDto> recommend = ItemSimilarity.recommend(userId);
            DecimalFormat df=new DecimalFormat("0.0");
            for (int i = 0; i < recommend.size(); i++) {
                if(recommend.get(i).getSuccessesNum()==0&&recommend.get(i).getSubmitNum()==0) {
                    recommend.get(i).setPassingRate("0.0%");
                }else{
                    recommend.get(i).setPassingRate(df.format((float) recommend.get(i).getSuccessesNum() / recommend.get(i).getSubmitNum() * 100) + "%");
                }
            }
            return recommend;
        }else {                                                      //否则就采用推荐用户没有做过的简单题目
            List<OJDto> ojDtos = ItemSimilarity.RandomSimplicity(userId);
            DecimalFormat df=new DecimalFormat("0.0");
            for (int i = 0; i < ojDtos.size(); i++) {
                if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                    ojDtos.get(i).setPassingRate("0.0%");
                }else{
                    ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");

                }
            }
            return ojDtos;
        }
    }

    //每日推荐
    @PostMapping("/DailyRecommend")
    public List<String> DailyRecommend(){
        List<Integer> heatTop3 = redisTemplate.opsForList().range("heatTop3", 0, -1);
        return ojMapper.heatTop3Name(heatTop3);
    }


    @PostMapping("/recommendByNum")
    public List<OJDto> RecommendByNum(){
        List<OJDto> ojDtos = ojMapper.AllOj();
        DecimalFormat df=new DecimalFormat("0.0");
        for (int i = 0; i < ojDtos.size(); i++) {
            if(ojDtos.get(i).getSuccessesNum()==0&&ojDtos.get(i).getSubmitNum()==0) {
                ojDtos.get(i).setPassingRate("0.0%");
            }else{
                ojDtos.get(i).setPassingRate(df.format((float) ojDtos.get(i).getSuccessesNum() / ojDtos.get(i).getSubmitNum() * 100) + "%");

            }
        }
        Collections.shuffle(ojDtos);
        return ojDtos.subList(0,5);
    }

    /***
     * 获取做题目排名前50的用户返回前端用来当作排行榜的数据
     * @return
     */
    @PostMapping("/TopRank")
    public List<Rank> TopRank(){
        List<Rank> ranks = userMapper.GetTop();
        for (Rank rank : ranks) {
            rank.setSubmitNum(ojMapper.getSubmitNum(rank.getUserId()));
            rank.setSuccessesNum(ojMapper.getSuccessNum(rank.getUserId()));
            DecimalFormat df=new DecimalFormat("0.0");
            if(rank.getSubmitNum()==0&&rank.getSuccessesNum()==0){
                rank.setSuccessRate("0.0%");
            }else {
                rank.setSuccessRate(df.format((float) rank.getSuccessesNum()/rank.getSubmitNum()*100)+"%");
            }
        }
        Collections.sort(ranks);
        System.out.println(ranks);
        return ranks;
    }

}
